const Koa = require('koa');
const router = require('koa-router')();
const json = require('koa-json');
const logger = require('koa-logger');
const bodyparser = require('koa-bodyparser');
const onerror = require('koa-onerror');
import { routerRegister } from './router';
import responseHandler from './middleware/response-handler';
import { errorLog, requestLog } from './utils/logger';

const app = new Koa();

onerror(app);
// 添加路由
routerRegister(router); //路由装箱


app.use(bodyparser())
   .use(json())
   .use(logger({
        transporter: requestLog,
    }))
   .use(responseHandler())
   .use(router.routes())
   .use(router.allowedMethods());

app.on('error', (err: any, ctx: any) => {
	errorLog(err.stack);
});

app.listen(3000);